#!/usr/bin/sh
set -xue

# QEMU path
QEMU=qemu-system-riscv64

# clang path and compiler flags
CC=clang
CFLAGS="-std=c11 -O2 -g3 -Wall -Wextra --target=riscv32-unknown-elf -fno-stack-protector -ffreestanding -nostdlib"

# build the kernel
$CC $CFLAGS -Wl,-Tkernel.ld -Wl,-Map=kernel.map -o kernel.elf \
    kernel.c

# start qemu
$QEMU -machine virt -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin \
    -nographic -serial mon:stdio --no-reboot -kernel kernel.elf